<?php

if (!defined("EXPONENT")) exit("");

$image = null;
if (isset($_GET['id'])) $image = $db->selectObject("imagegallery_image","id=".$_GET['id']);

if ($image) {
	$gallery = $db->selectObject("imagegallery_gallery","id=".$image->gallery_id);
	$loc = unserialize($gallery->location_data);
	$loc->int = $gallery->id;

	if (exponent_permissions_check("manage",$loc)) {
		$file = $db->selectObject('file','id='.$image->file_id);
		file::delete($file);
		$db->delete('file','id='.$image->file_id);
		// no need to delete thumbnail
    /*$file->filename = $image->thumbnail;
		file::delete($file);
		$file->filename = $image->enlarged;
		file::delete($file);
		$db->delete('file','id='.$image->file_id);*/
		$db->delete("imagegallery_image","id=".$image->id);
		$db->decrement('imagegallery_image','rank',1,'gallery_id='.$image->gallery_id.' AND rank > ' . $image->rank);
		exponent_flow_redirect();
	} else {
		echo SITE_403_HTML;
	}
} else echo SITE_404_HTML;

?>
